package nl.nhl.idp.Components.Network;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * Class that handles represents the data connection
 * @author Mark van der Wal
 *
 */
public class DataConnection 
{
	// Data members
	private Socket mSocket;
	private OutputStream mOutput;
	private boolean mIsConnected;
	
	/**
	 * Constructor 
	 * @param sock socket representing the connection
	 */
	public DataConnection(Socket sock)
	{
		mIsConnected = false;
		mSocket = sock;	
		try {
			mOutput = mSocket.getOutputStream();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * When the connection is still true it returns true
	 * @return true when when the connection is still connected
	 */
	public boolean IsConnected() { return mIsConnected; }
	
	/**
	 * Sets if the connection is connected
	 * @param rawr
	 */
	public void SetConnected(boolean rawr)
	{
		mIsConnected = rawr;
	}
	
	/**
	 * Stopts the connections
	 */
	public void Stop()
	{
		try 
		{
			mOutput.close();
			mSocket.close();
			mIsConnected = false;
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
	}
	
	/**
	 * Gets the output stream
	 * @return Outputstream if available
	 */
	public OutputStream getOutputStream()
	{
		if(mSocket != null)
			return mOutput;
		else
			return null;
	}
}
